<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>商品管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>     
		.guigeimg{display: inline-block; position: relative}
		.guigeimg_close{width: 25px;height: 22px;right: -14px;top:-14px;}
		.layui-table .layui-input { width: 120px;}
		#ggnamediv .layui-input,#ggvaldiv .layui-input{ display:inline;height:30px}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加商品{else}<i class="fa fa-pencil"></i> 编辑商品{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					{if $info['ischecked']==2}<blockquote class="layui-elem-quote" style="color:red">商品未审核通过，驳回原因：{$info.check_reason}</blockquote>{/if}
					<div class="layui-form form-label-w6">
						<div class="layui-tab" lay-filter="mytab">
							<ul class="layui-tab-title">
								<li class="layui-this" lay-id="1">商品基本信息</li>
								<li lay-id="2">商品详情</li>
							</ul>
							<div class="layui-tab-content">
								<div class="layui-tab-item layui-show">
									<input type="hidden" name="id" value="{$info['id']}"/>
								  
									<div class="layui-form-item">
										<label class="layui-form-label">兑换类型：</label>
										<div class="layui-input-inline" style="width:500px">
											<input type="radio" name="info[type]" value="0" title="默认" {if !$info['id'] || $info['type']==0}checked{/if} lay-filter="type"/>
											{if getcustom('scoreshop_wx_hongbao')}
											<input type="radio" name="info[type]" value="1" title="兑换红包" {if $info['type']==1}checked{/if} lay-filter="type"/>
											{/if}
											{if getcustom('scoreshop_to_money')}
											{if $bid ==0}
											<input type="radio" name="info[type]" value="2" title="兑换{:t('余额')}" {if $info['type']==2}checked{/if} lay-filter="type"/>
											{/if}
											{/if}
										</div>
									</div>
								  
	                
									<div class="layui-form-item">
										<label class="layui-form-label"><span class="redstar">*</span>商品名称：</label>
										<div class="layui-input-inline" style="width:300px">
											<input type="text" name="info[name]" lay-verify="required" lay-verType="tips" class="layui-input" value="{$info.name}">
										</div>
										<button type="button" class="layui-btn layui-btn-primary" onclick="showChooseProduct()">选择商城商品</button>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品主图：</label>
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="pic" upload-preview="picPreview" onclick="uploader(this)">上传图片</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picPreview" class="picsList-class-padding">
											<div class="layui-imgbox imgbox-required">
												<div class="layui-imgbox-img"><img src="{$info.pic}"/></div>
												<input type="text" name="info[pic]" id="pic" class="layui-input" value="{$info.pic}">
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品图片：</label>
										<input type="hidden" name="info[pics]" value="{$info['pics']}" id="pics">
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="pics" upload-preview="picList" >批量上传</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picList" class="picsList-class-padding">
											{if $info['pics']}
											{php}$pics = explode(',',$info['pics']);{/php}
											{foreach $pics as $pic}
											<div class="layui-imgbox">
												<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('pics','picList')" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a>
												<span class="layui-imgbox-img"><img src="{$pic}"></span>
											</div>
											{/foreach}{/if}
										</div>
									</div>
								
								
									
									<!-- <div class="layui-form-item">
										<label class="layui-form-label">商品服务：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[fuwupoint]" class="layui-input" value="{$info.fuwupoint}">
										</div>
										<div class="layui-form-mid layui-word-aux">多个用空格隔开,如: 7天退换 48小时发货 假一赔十</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品卖点：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[sellpoint]" class="layui-input" value="{$info.sellpoint}">
										</div>
										<div class="layui-form-mid layui-word-aux">在商品详情页标题下面展示卖点信息，建议60字以内</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品编码：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[procode]" class="layui-input" value="{$info.procode}">
										</div>
									</div> -->
									<div class="layui-form-item">
										<label class="layui-form-label">商品分类：</label>
										<div class="layui-input-inline">
											<select name="info[cid]">
											<option value="">--请选择--</option>
											{foreach $clist as $cv}
												<option value="{$cv['id']}" {if $cv['id']==$info['cid']}selected{/if}>{$cv['name']}</option>
												{foreach $cv['child'] as $v}
												<option value="{$v['id']}" {if $v['id']==$info['cid']}selected{/if}>&nbsp;&nbsp;&nbsp;{$v['name']}</option>
												{/foreach}
											{/foreach}
											</select>
										</div>
									</div>
									{if  getcustom('scoreshop_wx_hongbao')}	
									<div id="hongbao_content" {if $info['type'] !=1}style="display:none"{/if}>
										<div class="layui-form-item">
											<label class="layui-form-label">红包金额：</label>
											<div class="layui-input-inline">
												<input type="number" name="info[hongbao_money]" value="{$info.hongbao_money|default=1}" class="layui-input">
											</div>
											<div class="layui-form-mid layui-word-aux">用户购买后获得的微信红包额度</div>
										</div>
										<div class="layui-form-item">
											<label class="layui-form-label" >红包场景：</label>
											<div class="layui-input-inline" style="width:300px">
												<select name="info[scene_id]">
													<option value="">默认</option>
													<option value="PRODUCT_1" {if $info['scene_id'] == 'PRODUCT_1'}selected{/if}>商品促销</option>
													<option value="PRODUCT_2" {if $info['scene_id'] == 'PRODUCT_2'}selected{/if}>抽奖</option>
													<option value="PRODUCT_3" {if $info['scene_id'] == 'PRODUCT_3'}selected{/if}>虚拟物品兑奖</option>
													<option value="PRODUCT_4" {if $info['scene_id'] == 'PRODUCT_4'}selected{/if}>企业内部福利</option>
													<option value="PRODUCT_5" {if $info['scene_id'] == 'PRODUCT_5'}selected{/if}>渠道分润</option>
													<option value="PRODUCT_6" {if $info['scene_id'] == 'PRODUCT_6'}selected{/if}>保险回馈</option>
													<option value="PRODUCT_7" {if $info['scene_id'] == 'PRODUCT_7'}selected{/if}>彩票派奖</option>
													<option value="PRODUCT_8" {if $info['scene_id'] == 'PRODUCT_8'}selected{/if}>税务刮奖</option>
												</select>
											</div>
											<div class="layui-form-mid layui-word-aux">红包金额大于200或者小于1元时选择，选择场景时请确保商户平台[现金红包设置]内已申请相应的场景配额</div>
										</div>
									</div>
									{/if}
									{if  getcustom('scoreshop_to_money')}
									{if $bid ==0}
									<div id="money_content" {if $info['type'] !=2 }style="display:none"{/if}>
										<div class="layui-form-item">
											<label class="layui-form-label">兑换金额：</label>
											<div class="layui-input-inline">
												<input type="number" name="info[give_money]" value="{$info.give_money|default=1}" class="layui-input">
											</div>
											<div class="layui-form-mid layui-word-aux">用户购买后增加用户余额，配送模板请选择自动发货</div>
										</div>
									</div>
									{/if}
									{/if}

									<div class="layui-form-item">
										<label class="layui-form-label">每人限兑：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[buymax]" value="{$info.buymax|default=0}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">每人最多兑换多少件，0表示不限制</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">每人每天限兑：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[everyday_buymax]" value="{$info.everyday_buymax|default=0}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">每人每天最多兑换多少件，0表示不限制</div>
									</div>
									{if $bid==0 || $bset['product_showset']==1}
									<div class="layui-form-item">
										<label class="layui-form-label">会员价：</label>
										<div class="layui-input-inline" style="width:500px">
											<input type="radio" name="info[lvprice]" value="0" title="关闭" {if !$info['id'] || $info['lvprice']==0}checked{/if} lay-filter="lvpriceset"/>
											<input type="radio" name="info[lvprice]" value="1" title="开启" {if $info['lvprice']==1}checked{/if} lay-filter="lvpriceset"/>
										</div>
									</div>
									{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">设置价格：</label>
										<div class="layui-input-inline" style="width:auto">
											<table id="ggvaldiv" class="layui-table">

											</table>
										</div>
									</div>

								<div id="defaultcontent" {if getcustom('scoreshop_wx_hongbao') && $info['type'] ==1}style="display:none"{/if}>
								<div class="layui-form-item">
										<label class="layui-form-label">销量：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sales]" value="{$info.sales|default=0}" class="layui-input">
											<input type="hidden" name="info[oldsales]" value="{$info.sales|default=0}" class="layui-input">
										</div>
									</div>
									
									{if getcustom('scoreshop_guige')}
									<div class="layui-form-item">
										<label class="layui-form-label">多规格：</label>
										<div class="layui-input-inline" style="width:500px">
											<input type="radio" name="info[guigeset]" value="0" title="关闭" {if !$info['id'] || $info['guigeset']==0}checked{/if} lay-filter="guigeset"/>
											<input type="radio" name="info[guigeset]" value="1" title="开启" {if $info['guigeset']==1}checked{/if} lay-filter="guigeset"/>
										</div>
									</div>
									{/if}

									<div class="layui-form-item" id="setgg" {if !$info['id'] || $info['guigeset']==0}style="display:none"{/if}>
									<label class="layui-form-label">设置规格：</label>
									<div class="layui-input-inline" style="width:auto">
										<table id="ggnamediv"  class="layui-table" style="width:600px">
											<thead>
											<tr>
												<th>规格分组</th>
												<th>规格名称</th>
												<th>操作</th>
											</tr>
											</thead>
											{php} $guigedata = json_decode($info['guigedata']);{/php}
											{if $info['guigeset']==1 && $guigedata}
											{foreach $guigedata as $k=>$gg}
											<tr>
												<td><input type="text" class="layui-input" name="ggname" value="{$gg->title}" style="width:120px"/></td>
												<td>
													{foreach $gg->items as $k2=>$ggitem}
													<div><input type="text" class="layui-input"style="width:180px" value="{$ggitem->title}" placeholder="请输入规格名称">
														{if $k2==0}
														<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button>
														{else}
														<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().remove()" style="margin-top:-3px;"><i class="fa fa-remove" style="font-size:14px!important"></i></button>
														{/if}
													</div>
													{/foreach}
												</td>
												{if $k==0}
												<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
												{else}
												<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>
												{/if}
											</tr>
											{/foreach}
											{else}
											<tr>
												<td><input type="text" class="layui-input" name="ggname" value="规格" style="width:120px"/></td>
												<td><div><input type="text" class="layui-input" style="width:180px" value="默认规格" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button></div></td>
												<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
											</tr>
											{/if}
										</table>
										<div class="layui-word-aux">提示：先点击“添加按钮”添加规格分组，如：“颜色”，“尺码”，若只有一种规格则不需要添加规格分组；<br/>然后分别点击"＋"号添加规格名称，如：“红色”，“蓝色”；“大号”，“小号”；<br/>设置完成后点击“刷新规格项目表”按钮进行编辑各个规格的价格、库存等信息</div>
										<button type="button"  class="layui-btn layui-btn-sm layui-btn-primary" onclick="refreshgg()"><i class="fa fa-refresh" style="font-size:14px!important"></i>刷新规格项目表</button>
										<input type="hidden" name="specs" value=""/>
									</div>
								</div>
									<div class="layui-form-item">
										<label class="layui-form-label">配送模板：</label>
										<div class="layui-input-inline" style="width:500px">
											<input type="radio" name="info[freighttype]" value="1" title="全部模板" {if !$info['id'] || $info['freighttype']==1}checked{/if} lay-filter="freighttypeset"/>
											<input type="radio" name="info[freighttype]" value="0" title="选择模板" {if $info['id'] && $info['freighttype']==0}checked{/if} lay-filter="freighttypeset"/>
											<input type="radio" name="info[freighttype]" value="3" title="自动发货" {if $info['id'] && $info['freighttype']==3}checked{/if} lay-filter="freighttypeset"/>
											<input type="radio" name="info[freighttype]" value="4" title="在线卡密" {if $info['id'] && $info['freighttype']==4}checked{/if} lay-filter="freighttypeset"/>
										</div>
										
										<div id="freighttype3" style="{if $info['freighttype']!=3}display:none{/if}">
											<div class="layui-form-item">
												<label class="layui-form-label"></label>
												<div class="layui-input-inline" style="width:500px">
													<textarea type="text" name="info[freightcontent]" placeholder="请输入发货信息" class="layui-textarea">{$info.freightcontent}</textarea>
												</div>
											</div>
										</div>
										<div id="freighttype4" style="{if $info['freighttype']!=4}display:none{/if}">
											<div class="layui-form-item">
												<label class="layui-form-label"></label>
												<div class="layui-form-mid">请保存商品信息后在商品列表中上传卡密信息；用户购买几件将发送几个卡密信息</div>
											</div>
										</div>

										<div id="setfreight" style="clear:both;{if !$info['id'] || $info['freighttype']!=0}display:none{/if}">
											<label class="layui-form-label"></label>
											<div class="layui-input-inline" style="width:auto">
												<table id="setfreightdiv"  class="layui-table" style="width:500px">
													<thead>
													<tr>
														<th>模板ID</th>
														<th>模板名称</th>
														<th>操作</th>
													</tr>
													</thead>
													
													{if $freightdata}
													{foreach $freightdata as $k=>$ff}
													<tr class="freightlisttr"><td>{$ff.id}</td><td>{$ff.name}</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delfreight(this,{$ff.id})">删除</button></td></tr>
													{/foreach}
													{/if}
													<tr id="freightaddtr">
														<td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseFreight()">添加</button></td>
													</tr>
												</table>
												<input type="hidden" name="info[freightdata]" value="{$info.freightdata}"/>
											</div>
										</div>
									</div>
									<script>
									var chooseFreightLayer;
									function showChooseFreight(){
										chooseFreightLayer = layer.open({type:2,title:'选择配送模板',content:"{:url('Freight/choosefreight')}",area:['1000px','600px'],shadeClose:true});
									}
									function chooseFreight(fid,fname){
										layer.close(chooseFreightLayer);
										var freightlistids = [];
										var isadd = 0;
										$('.freightlisttr').each(function(){
											var thisfid = $(this).find('td:eq(0)').html();
											if(thisfid == fid){
												isadd = 1
												dialog('该配送模板已添加过了');
											}
											freightlistids.push(thisfid)
										})
										if(isadd == 0){
											freightlistids.push(fid)
											$("input[name='info[freightdata]']").val(freightlistids.join(','));
											$('#freightaddtr').before('<tr class="freightlisttr"><td>'+fid+'</td><td>'+fname+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delfreight(this,'+fid+')">删除</button></td></tr>');
										}
										console.log(freightlistids)
									}
									function delfreight(obj,fid){
										$(obj).parent().parent().remove();
										var freightlistids = [];
										$('.freightlisttr').each(function(){
											freightlistids.push($(this).find('td:eq(0)').html())
										})
										$("input[name='info[freightdata]']").val(freightlistids.join(','));
									}
									</script>
							</div>
							
									{if $bid==0 || $bset['commission_canset']==1}
									<div class="layui-form-item">
										<label class="layui-form-label">分销设置：</label>
										<div class="layui-input-block" style="width:900px">
											<input type="radio" name="info[commissionset]" value="0" {if !$info['id'] || $info['commissionset']==0}checked{/if} title="按照{:t('会员')}等级" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="1" {if $info['commissionset']==1}checked{/if} title="单独设置提成比例" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="2" {if $info['commissionset']==2}checked{/if} title="单独设置提成金额" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="3" {if $info['commissionset']==3}checked{/if} title="分销送{:t('积分')}" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="5" {if $info['commissionset']==5}checked{/if} title="提成比例+{:t('积分')}" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="-1" {if $info['commissionset']==-1}checked{/if} title="不参与分销" lay-filter="commissionset">
										</div>
										<div class="layui-form-mid layui-word-aux">按照{:t('会员')}等级：按照{:t('会员')}等级中设置的提成比例进行提成分配，提成=对应{:t('会员')}等级的提成比例×{$jiesuantypeDesc}×购买数量<br>
											单独设置提成比例：按照单独设置的提成比例进行提成分配，提成=设置的百分比×{$jiesuantypeDesc}×购买数量<br>
											单独设置提成金额：按照单独设置的提成金额进行提成分配，提成=提成金额×购买数量<br>
											分销送{:t('积分')}：分销提成不给{:t('佣金')}而是给{:t('积分')}，得到的积分=提成{:t('积分')}×购买数量<br>
											提成比例+{:t('积分')}：按照单独设置的提成比例+{:t('积分')}进行提成分配，提成=设置的百分比×{$jiesuantypeDesc}×购买数量+{:t('积分')}×购买数量<br>
											注：以金额方式分成时，如商品为全部积分兑换，则分成金额为0
										</div>
									</div>
									{php}
									$commissiondata1 = json_decode($info['commissiondata1'],true);
									if(!$commissiondata1) $commissiondata1 = [];
									$commissiondata2 = json_decode($info['commissiondata2'],true);
									if(!$commissiondata2) $commissiondata2 = [];
									$commissiondata3 = json_decode($info['commissiondata3'],true);
									if(!$commissiondata3) $commissiondata3 = [];
									$commissiondata5 = json_decode($info['commissiondata5'],true);
									if(!$commissiondata5) $commissiondata5 = [];
									{/php}
								<div id="commissionset1" class="commissionset" {if $info['commissionset']!=1}style="display:none"{/if}>
									{if !$aglevellist}
									<div class="layui-form-item">
										<label class="layui-form-label">提成比例：</label>
										<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
									</div>
									{else}
									{foreach $aglevellist as $level}
									<div class="layui-form-item">
										<label class="layui-form-label">{$level.name}：</label>
										<div class="layui-input-inline layui-module-itemL">
											<div> 一级(%) </div>
											<input type="text" name="commissiondata1[{$level.id}][commission1]" class="layui-input" value="{$commissiondata1[$level['id']]['commission1']}">
										</div>
										{if $level['can_agent']>1}
										<div class="layui-input-inline layui-module-itemL">
											<div>二级(%)</div>
											<input type="text" name="commissiondata1[{$level.id}][commission2]" class="layui-input" value="{$commissiondata1[$level['id']]['commission2']}">
										</div>
										{/if}
										{if $level['can_agent']>2}
										<div class="layui-input-inline layui-module-itemL">
											<div>三级(%)</div>
											<input type="text" name="commissiondata1[{$level.id}][commission3]" class="layui-input" value="{$commissiondata1[$level['id']]['commission3']}">
										</div>
										{/if}
									</div>
									{/foreach}
									{/if}
								</div>
								<div id="commissionset2" class="commissionset" {if $info['commissionset']!=2}style="display:none"{/if}>
									{if !$aglevellist}
									<div class="layui-form-item">
										<label class="layui-form-label">提成金额：</label>
										<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
									</div>
									{else}
									{foreach $aglevellist as $level}
									<div class="layui-form-item">
										<label class="layui-form-label">{$level.name}：</label>
										<div class="layui-input-inline layui-module-itemL">
											<div> 一级(元) </div>
											<input type="text" name="commissiondata2[{$level.id}][commission1]" class="layui-input" value="{$commissiondata2[$level['id']]['commission1']}">
										</div>
										{if $level['can_agent']>1}
										<div class="layui-input-inline layui-module-itemL">
											<div>二级(元)</div>
											<input type="text" name="commissiondata2[{$level.id}][commission2]" class="layui-input" value="{$commissiondata2[$level['id']]['commission2']}">
										</div>
										{/if}
										{if $level['can_agent']>2}
										<div class="layui-input-inline layui-module-itemL">
											<div>三级(元)</div>
											<input type="text" name="commissiondata2[{$level.id}][commission3]" class="layui-input" value="{$commissiondata2[$level['id']]['commission3']}">
										</div>
										{/if}
									</div>
									{/foreach}
									{/if}
								</div>
								<div id="commissionset3" class="commissionset" {if $info['commissionset']!=3}style="display:none"{/if}>
									{if !$aglevellist}
									<div class="layui-form-item">
										<label class="layui-form-label">提成{:t('积分')}：</label>
										<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
									</div>
									{else}
									{foreach $aglevellist as $level}
									<div class="layui-form-item">
										<label class="layui-form-label">{$level.name}：</label>
										<div class="layui-input-inline layui-module-itemL">
											<div> 一级({:t('积分')}) </div>
											<input type="text" name="commissiondata3[{$level.id}][commission1]" class="layui-input" value="{$commissiondata3[$level['id']]['commission1']}">
										</div>
										{if $level['can_agent']>1}
										<div class="layui-input-inline layui-module-itemL">
											<div>二级({:t('积分')})</div>
											<input type="text" name="commissiondata3[{$level.id}][commission2]" class="layui-input" value="{$commissiondata3[$level['id']]['commission2']}">
										</div>
										{/if}
										{if $level['can_agent']>2}
										<div class="layui-input-inline layui-module-itemL">
											<div>三级({:t('积分')})</div>
											<input type="text" name="commissiondata3[{$level.id}][commission3]" class="layui-input" value="{$commissiondata3[$level['id']]['commission3']}">
										</div>
										{/if}
									</div>
									{/foreach}
									{/if}
								</div>
								<div id="commissionset5" class="commissionset" {if $info['commissionset']!=5}style="display:none"{/if}>
									{if !$aglevellist}
									<div class="layui-form-item">
										<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
									</div>
									{else}
									{foreach $aglevellist as $level}
									<div class="layui-form-item">
										<label class="layui-form-label">{$level.name}：</label>
										<div class="layui-input-inline layui-module-itemL">
											<div> 一级(%) </div>
											<input type="text" name="commissiondata5[{$level.id}][commission1][money]" class="layui-input" value="{$commissiondata5[$level['id']]['commission1'][money]}">
										</div>
										{if $level['can_agent']>1}
										<div class="layui-input-inline layui-module-itemL">
											<div>二级(%)</div>
											<input type="text" name="commissiondata5[{$level.id}][commission2][money]" class="layui-input" value="{$commissiondata5[$level['id']]['commission2'][money]}">
										</div>
										{/if}
										{if $level['can_agent']>2}
										<div class="layui-input-inline layui-module-itemL">
											<div>三级(%)</div>
											<input type="text" name="commissiondata5[{$level.id}][commission3][money]" class="layui-input" value="{$commissiondata5[$level['id']]['commission3'][money]}">
										</div>
										{/if}
									</div>
									{/foreach}
									{/if}
									{if !$aglevellist}
									{else}
									{foreach $aglevellist as $level}
									<div class="layui-form-item">
										<label class="layui-form-label">{$level.name}：</label>
										<div class="layui-input-inline layui-module-itemL">
											<div>一级({:t('积分')})</div>
											<input type="text" name="commissiondata5[{$level.id}][commission1][score]" class="layui-input" value="{$commissiondata5[$level['id']]['commission1'][score]}">
										</div>
										{if $level['can_agent']>1}
										<div class="layui-input-inline layui-module-itemL">
											<div>二级({:t('积分')})</div>
											<input type="text" name="commissiondata5[{$level.id}][commission2][score]" class="layui-input" value="{$commissiondata5[$level['id']]['commission2'][score]}">
										</div>
										{/if}
										{if $level['can_agent']>2}
										<div class="layui-input-inline layui-module-itemL">
											<div>三级({:t('积分')})</div>
											<input type="text" name="commissiondata5[{$level.id}][commission3][score]" class="layui-input" value="{$commissiondata5[$level['id']]['commission3'][score]}">
										</div>
										{/if}
									</div>
									{/foreach}
									{/if}
								</div>
								{/if}

								  {if getcustom('scoreshop_fenhong') && $bid==0 && ($auth_data=='all' || in_array('gdfenhong',$auth_data) || in_array('teamfenhong',$auth_data) || in_array('areafenhong',$auth_data))}
								  <div class="layui-form-item">
									  <label class="layui-form-label">分红设置：</label>
									  <div class="layui-input-block" style="width:800px">
										  <input type="radio" name="info[fenhongset]" value="1" {if !$info['id'] || $info['fenhongset']==1}checked{/if} title="参与" lay-filter="fenhongset">
										  <input type="radio" name="info[fenhongset]" value="0" {if $info['id'] && $info['fenhongset']==0}checked{/if} title="不参与" lay-filter="fenhongset">
									  </div>
								  </div>
								  <div id="fenhongset" {if $info['id'] && $info['fenhongset']==0}style="display:none"{/if}>
								  {if $auth_data=='all' || in_array('teamfenhong',$auth_data)}
								  <div class="layui-form-item">
									  <label class="layui-form-label">团队分红：</label>
									  <div class="layui-input-block" style="width:700px">
										  <input type="radio" name="info[teamfenhongset]" value="0" {if !$info['id'] || $info['teamfenhongset']==0}checked{/if} title="按照{:t('会员')}等级" lay-filter="teamfenhongset">
										  <input type="radio" name="info[teamfenhongset]" value="1" {if $info['teamfenhongset']==1}checked{/if} title="单独设置分红比例" lay-filter="teamfenhongset">
										  <input type="radio" name="info[teamfenhongset]" value="2" {if $info['teamfenhongset']==2}checked{/if} title="单独设置分红金额" lay-filter="teamfenhongset">
										  <input type="radio" name="info[teamfenhongset]" value="-1" {if $info['teamfenhongset']==-1}checked{/if} title="不参与分红" lay-filter="teamfenhongset">
									  </div>
									  <div class="layui-form-mid layui-word-aux">开启后可以拿到团队中所有{:t('会员')}的所有兑换订单的分红金额或比例，请先在[{:t('会员')}]-[等级及分销]设置分红级数</div>
								  </div>
								  {php}
								  $teamfenhongdata1 = json_decode($info['teamfenhongdata1'],true);
								  if(!$teamfenhongdata1) $teamfenhongdata1 = [];
								  $teamfenhongdata2 = json_decode($info['teamfenhongdata2'],true);
								  if(!$teamfenhongdata2) $teamfenhongdata2  = [];
								  {/php}
								  <div id="teamfenhongset1" {if $info['teamfenhongset']!=1}style="display:none"{/if}>
								  <div class="layui-form-item">
									  <label class="layui-form-label">分红比例：</label>
									  {if !$teamlevellist}<div class="layui-form-mid" style="color:red">未设置具有团队分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
									  {foreach $teamlevellist as $level}
									  <div class="layui-input-inline layui-module-itemL">
											<div> {$level.name}(%) </div>
										  <input type="text" name="teamfenhongdata1[{$level.id}][commission]" class="layui-input" value="{$teamfenhongdata1[$level['id']]['commission']}">
									  </div>
									  {/foreach}
								  </div>
							  </div>
								<div id="teamfenhongset2" {if $info['teamfenhongset']!=2}style="display:none"{/if}>
								<div class="layui-form-item">
									<label class="layui-form-label">分红金额：</label>
									{if !$teamlevellist}<div class="layui-form-mid" style="color:red">未设置具有团队分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
									{foreach $teamlevellist as $level}
									<div class="layui-input-inline layui-module-itemL">
										<div> {$level.name}(元) </div>
										<input type="text" name="teamfenhongdata2[{$level.id}][commission]" class="layui-input" value="{$teamfenhongdata2[$level['id']]['commission']}">
									</div>
									{/foreach}
								</div>
							</div>
							  {/if}
							  {if $auth_data=='all' || in_array('gdfenhong',$auth_data)}
							  <div class="layui-form-item">
								  <label class="layui-form-label">股东分红：</label>
								  <div class="layui-input-block" style="width:700px">
									  <input type="radio" name="info[gdfenhongset]" value="0" {if !$info['id'] || $info['gdfenhongset']==0}checked{/if} title="按照会员等级" lay-filter="gdfenhongset">
									  <input type="radio" name="info[gdfenhongset]" value="1" {if $info['gdfenhongset']==1}checked{/if} title="单独设置分红比例" lay-filter="gdfenhongset">
									  <input type="radio" name="info[gdfenhongset]" value="2" {if $info['gdfenhongset']==2}checked{/if} title="单独设置分红金额" lay-filter="gdfenhongset">
									  <input type="radio" name="info[gdfenhongset]" value="-1" {if $info['gdfenhongset']==-1}checked{/if} title="不参与分红" lay-filter="gdfenhongset">
								  </div>
								  <div class="layui-form-mid layui-word-aux">用于股东分红或合伙人分红，开启后相应等级的所有{:t('会员')}平均分摊设置的分红金额或比例</div>
							  </div>
							  {php}
							  $gdfenhongdata1 = json_decode($info['gdfenhongdata1'],true);
							  if(!$gdfenhongdata1) $gdfenhongdata1 = [];
							  $gdfenhongdata2 = json_decode($info['gdfenhongdata2'],true);
							  if(!$gdfenhongdata2) $gdfenhongdata2  = [];
							  {/php}
							  <div id="gdfenhongset1" {if $info['gdfenhongset']!=1}style="display:none"{/if}>
							  <div class="layui-form-item">
								  <label class="layui-form-label">分红比例：</label>
								  {if !$gdlevellist}<div class="layui-form-mid" style="color:red">未设置具有股东分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
								  {foreach $gdlevellist as $level}
								  <div class="layui-input-inline layui-module-itemL">
										<div> {$level.name}(%) </div>
									  <input type="text" name="gdfenhongdata1[{$level.id}][commission]" class="layui-input" value="{$gdfenhongdata1[$level['id']]['commission']}">
								  </div>
								  {/foreach}
							  </div>
						  </div>
						  <div id="gdfenhongset2" {if $info['gdfenhongset']!=2}style="display:none"{/if}>
						  <div class="layui-form-item">
							  <label class="layui-form-label">分红金额：</label>
							  {if !$gdlevellist}<div class="layui-form-mid" style="color:red">未设置具有股东分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
							  {foreach $gdlevellist as $level}
							  <div class="layui-input-inline layui-module-itemL">
									<div> {$level.name}(元) </div>
								  <input type="text" name="gdfenhongdata2[{$level.id}][commission]" class="layui-input" value="{$gdfenhongdata2[$level['id']]['commission']}">
							  </div>
							  {/foreach}
						  </div>
						  </div>
						  {/if}
						  {if $auth_data=='all' || in_array('areafenhong',$auth_data)}
						  <div class="layui-form-item">
							  <label class="layui-form-label">区域代理分红：</label>
							  <div class="layui-input-block" style="width:700px">
								  <input type="radio" name="info[areafenhongset]" value="0" {if !$info['id'] || $info['areafenhongset']==0}checked{/if} title="按照会员等级" lay-filter="areafenhongset">
								  <input type="radio" name="info[areafenhongset]" value="1" {if $info['areafenhongset']==1}checked{/if} title="单独设置分红比例" lay-filter="areafenhongset">
								  <input type="radio" name="info[areafenhongset]" value="2" {if $info['areafenhongset']==2}checked{/if} title="单独设置分红金额" lay-filter="areafenhongset">
								  <input type="radio" name="info[areafenhongset]" value="-1" {if $info['areafenhongset']==-1}checked{/if} title="不参与分红" lay-filter="areafenhongset">
							  </div>
							  <div class="layui-form-mid layui-word-aux">设置分红比例或分红金额后该等级的同一个代理区域的人平均分摊所有商城内该区域的订单的分红提成比例或分红金额</div>
						  </div>
						  {php}
						  $areafenhongdata1 = json_decode($info['areafenhongdata1'],true);
						  if(!$areafenhongdata1) $areafenhongdata1 = [];
						  $areafenhongdata2 = json_decode($info['areafenhongdata2'],true);
						  if(!$areafenhongdata2) $areafenhongdata2  = [];
						  {/php}
						  <div id="areafenhongset1" {if $info['areafenhongset']!=1}style="display:none"{/if}>
						  <div class="layui-form-item">
							  <label class="layui-form-label">分红比例：</label>
							  {if !$areafhlevellist}<div class="layui-form-mid" style="color:red">未设置具有区域代理分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
							  {foreach $areafhlevellist as $level}
							  <div class="layui-input-inline layui-module-itemL">
									<div> {$level.name}(%) </div>
								  <input type="text" name="areafenhongdata1[{$level.id}][commission]" class="layui-input" value="{$areafenhongdata1[$level['id']]['commission']}">
							  </div>
							  {/foreach}
						  </div>
						  </div>
						  <div id="areafenhongset2" {if $info['areafenhongset']!=2}style="display:none"{/if}>
						  <div class="layui-form-item">
							  <label class="layui-form-label">分红金额：</label>
							  {if !$areafhlevellist}<div class="layui-form-mid" style="color:red">未设置具有区域代理分红权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置</div>{/if}
							  {foreach $areafhlevellist as $level}
							  <div class="layui-input-inline layui-module-itemL">
									<div> {$level.name}(元) </div>
								  <input type="text" name="areafenhongdata2[{$level.id}][commission]" class="layui-input" value="{$areafenhongdata2[$level['id']]['commission']}">
							  </div>
							  {/foreach}
						  </div>
						  </div>
						  {/if}
						  </div>
						  {/if}

					{if getcustom('plug_zhiming')}
					<div class="layui-form-item">
						<label class="layui-form-label">门店分成金额：</label>
						<div class="layui-input-inline" style="width: 300px">
							<input type="radio" name="info[commission_money_type]" value="0" title="按比例" {if !$info['id'] || $info['commission_money_type']==0}checked{/if} lay-filter="commission_money_type">
							<input type="radio" name="info[commission_money_type]" value="1" title="固定数量" {if $info['id'] && $info['commission_money_type']==1}checked{/if} lay-filter="commission_money_type">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"></label>
						<div class="commission_money_type commission_money_type0" {if $info['commission_money_type'] != 0} style="display:none;"{/if}>
							<div class="layui-input-inline">
								<input type="number" min="0" max="100" name="info[commission_money_percent]" value="{$info.commission_money_percent|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">%</div>
						</div>
						<div class="commission_money_type commission_money_type1" {if $info['commission_money_type'] != 1} style="display:none;"{/if}>
							<div class="layui-input-inline">
								<input type="number" min="0" max="100" name="info[commission_money]" value="{$info.commission_money|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">元</div>
						</div>
						<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">分成转入核销管理员对应会员账户</div>
	  				</div>
					<div class="layui-form-item">
						<label class="layui-form-label">门店分成{:t('积分')}：</label>
						<div class="layui-input-inline" style="width: 300px">
							<input type="radio" name="info[commission_score_type]" value="0" title="按比例" {if !$info['id'] || $info['commission_score_type']==0}checked{/if} lay-filter="commission_score_type">
							<input type="radio" name="info[commission_score_type]" value="1" title="固定数量" {if $info['id'] && $info['commission_score_type']==1}checked{/if} lay-filter="commission_score_type">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"></label>
						<div class="commission_score_type commission_score_type0" {if $info['commission_score_type'] != 0} style="display:none;"{/if}>
							<div class="layui-input-inline">
								<input type="number" min="0" max="100" name="info[commission_score_percent]" value="{$info.commission_score_percent|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">%</div>
						</div>
						<div class="commission_score_type commission_score_type1" {if $info['commission_score_type'] != 1} style="display:none;"{/if}>
							<div class="layui-input-inline">
								<input type="number" min="0" max="100" name="info[commission_score]" value="{$info.commission_score|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">个</div>
						</div>
						<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">使用{:t('积分')}支付的订单，{:t('积分')}分成转入核销管理员对应会员账户，{:t('积分')}计算向下取整</div>
					</div>
				  {/if}
				  					{if getcustom('plug_tengrui')}
			                        <div class="layui-form-item">
			                            <label class="layui-form-label">认证{:t('会员')}：</label>
			                            <div class="layui-input-inline">
			                                <input type="radio" name="info[is_rzh]" value="0" {if !$info['id'] || $info['is_rzh']==0}checked{/if} title="否"/>
			                                <input type="radio" name="info[is_rzh]" value="1" {if $info['id'] && $info['is_rzh']==1}checked{/if} title="是"/>
			                            </div>
			                        </div>
			                        <div class="layui-form-item">
			                            <label class="layui-form-label">{:t('会员')}关系：</label>
			                            <div class="layui-input-inline" style="width:500px">
			                            <input type="radio" name="info[relation_type]" value="-1" {if !$info['id'] || $info['relation_type']==-1}checked{/if} title="所有"/>
			                                <input type="radio" name="info[relation_type]" value="0" {if $info['id'] && $info['relation_type']==0}checked{/if} title="业主"/>
			                                <input type="radio" name="info[relation_type]" value="1" {if $info['id'] && $info['relation_type']==1}checked{/if} title="家属"/>
			                                <input type="radio" name="info[relation_type]" value="2" {if $info['id'] && $info['relation_type']==2}checked{/if} title="租户"/>
			                                <input type="radio" name="info[relation_type]" value="3" {if $info['id'] && $info['relation_type']==3}checked{/if} title="买断"/>
			                                <input type="radio" name="info[relation_type]" value="4" {if $info['id'] && $info['relation_type']==4}checked{/if} title="租用"/>
			                            </div>
			                        </div>
			                        <div class="layui-form-item">
			                            <label class="layui-form-label">一户仅限一次：</label>
			                            <div class="layui-input-inline">
			                                <input type="radio" name="info[house_status]" value="0" {if $info['id'] && $info['house_status']==0}checked{/if} title="否"/>
			                                <input type="radio" name="info[house_status]" value="1" {if !$info['id'] || $info['house_status']==1}checked{/if} title="是"/>
			                            </div>
			                            <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">需是认证用户，且同一个小区的同一户只限一人购买，即一户仅限一次</div>
			                        </div>
			                        <div class="layui-form-item">
			                            <label class="layui-form-label">授权小区：</label>
			                            <div class="layui-input-inline" style="width:500px">
			                                <input type="radio" name="info[group_status]" value="0" {if $info['group_status']==0}checked{/if} title="关闭" lay-filter="group_status"/>
			                                <input type="radio" name="info[group_status]" value="1" {if $info['group_status']==1}checked{/if} title="开启" lay-filter="group_status"/>
			                            </div>
			                            <div class="group_status1 fwtypeExtend" style="clear:both;{if $info['group_status']!=1}display:none{/if}">
			                                <label class="layui-form-label"></label>
			                                <div class="layui-input-inline" style="width:auto">
			                                    <table id="setgroupdiv"  class="layui-table" style="width:500px">
			                                        <thead>
			                                        <tr>
			                                            <th>小区ID</th>
			                                            <th>小区名称</th>
			                                            <th>操作</th>
			                                        </tr>
			                                        </thead>
			                                        {if $groupdata}
			                                        {foreach $groupdata as $gk=>$gv}
			                                        <tr class="grouplisttr"><td>{$gv.id}</td><td>{$gv.fullName}</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGroup(this,{$gv.id})">删除</button></td></tr>
			                                        {/foreach}
			                                        {/if}
			                                        <tr id="groupaddtr">
			                                            <td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseGroup()">添加</button></td>
			                                        </tr>
			                                    </table>
			                                    <input type="hidden" name="info[group_ids]" value="{$info.group_ids}"/>
			                                </div>
			                            </div>
			                            <script>
			                            var chooseGroupLayer;
			                            function showChooseGroup(){
			                                chooseGroupLayer = layer.open({type:2,title:'选择分组',content:"{:url('MemberTrGroup/choosegroup')}",area:['1000px','600px'],shadeClose:true});
			                            }
			                            function chooseGroup(fid,fname){
			                                layer.close(chooseGroupLayer);
			                                var group_ids = [];
			                                var isadd = 0;
			                                $('.grouplisttr').each(function(){
			                                    var thisfid = $(this).find('td:eq(0)').html();
			                                    if(thisfid == fid){
			                                        isadd = 1
			                                        dialog('该分组已添加过了');
			                                    }
			                                    group_ids.push(thisfid)
			                                })
			                                if(isadd == 0){
			                                    group_ids.push(fid)
			                                    $("input[name='info[group_ids]']").val(group_ids.join(','));
			                                    $('#groupaddtr').before('<tr class="grouplisttr"><td>'+fid+'</td><td>'+fname+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGroup(this,'+fid+')">删除</button></td></tr>');
			                                }
			                                console.log(group_ids)
			                            }
			                            function delGroup(obj,fid){
			                                $(obj).parent().parent().remove();
			                                var group_ids = [];
			                                $('.grouplisttr').each(function(){
			                                    group_ids.push($(this).find('td:eq(0)').html())
			                                })
			                                $("input[name='info[group_ids]']").val(group_ids.join(','));
			                            }
			                            </script>
			                        </div>
				                    {/if}
									<div class="layui-form-item">
										<label class="layui-form-label">序号：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sort]" value="{$info.sort|default=0}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">用于排序,越大越靠前</div>
									</div>

									{if $bid==0 || $bset['product_showset']==1}
									<div class="layui-form-item">
										<label class="layui-form-label">显示条件：</label>
										<div class="layui-input-inline" style="width:800px">
											<input type="checkbox" name="info[showtj][]" value="-1" title="所有人" lay-skin="primary" {if !$info['id'] || in_array('-1',$info['showtj'])}checked{/if}/>
											<input type="checkbox" name="info[showtj][]" value="0" title="关注用户" lay-skin="primary" {if in_array('0',$info['showtj'])}checked{/if}/>
											{foreach $levellist as $v}
											<input type="checkbox" name="info[showtj][]" value="{$v.id}" title="{$v.name}" lay-skin="primary" {if in_array($v['id'],$info['showtj'])}checked{/if}/>
											{/foreach}
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">购买条件：</label>
										<div class="layui-input-inline" style="width:800px">
											<input type="checkbox" name="info[gettj][]" value="-1" title="所有人" lay-skin="primary" {if !$info['id'] || in_array('-1',$info['gettj'])}checked{/if} lay-filter="gettjset"/>
											<input type="checkbox" name="info[gettj][]" value="0" title="关注用户" lay-skin="primary" {if in_array('0',$info['gettj'])}checked{/if}/>
											{foreach $levellist as $v}
											<input type="checkbox" name="info[gettj][]" value="{$v.id}" title="{$v.name}" lay-skin="primary" {if in_array($v['id'],$info['gettj'])}checked{/if}/>
											{/foreach}
										</div>
									</div>
									{/if}

									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-inline">
											<input type="radio" name="info[status]" value="1" title="已上架" {if !$info['id'] || $info['status']==1}checked{/if}/>
											<input type="radio" name="info[status]" value="0" title="未上架" {if $info['id'] && $info['status']==0}checked{/if}/>
										</div>
									</div>
									
									<div class="layui-form-item">
										<label class="layui-form-label"></label>
										<div class="layui-input-block">
											<button class="layui-btn layui-btn-normal" onclick="gonext(2)">下一步:编辑商品详情</button>
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>

								</div>
								<div class="layui-tab-item">
									<!-- 详情编辑器 -->
									<?php 
									$pagetitle='商品详情';
									$pagedata= $info['detail'] && json_decode($info['detail']) ? $info['detail'] : '[{"id":"M0000000000000","temp":"richtext","params":{bgcolor:"#FFFFFF",margin_x:"0",margin_y:"5",padding_x:"10",padding_y:"10","quanxian":{"all":true},"platform":{"all":true}},"data":"","other":"","content":""}]';
									?>
									{include file="designer_page/designer_editor" /}
									<div class="layui-form-item">
										<div class="layui-input-block">
											<button class="layui-btn layui-btn-normal" onclick="gonext(1)">上一步:编辑基本信息</button>
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
	<script>
		layui.form.on('radio(type)',function(data){
			if(data.value == 1){
				$('#money_content').hide();
				$('#defaultcontent').hide();
				$('#hongbao_content').show();
			}else if(data.value==2){
				$('#defaultcontent').hide();
				$('#hongbao_content').hide();
				$('#money_content').show();
			}else{
				$('#defaultcontent').show();
				$('#hongbao_content').hide();
				$('#money_content').hide();
			}
		})
		layui.form.on('radio(group_status)',function(data){
	        if(data.value == 1){
	            $('.group_status1').show();
	        }else{
	            $('.group_status1').hide();
	        }
	    })
		var lvprice = $("input[name='info[lvprice]']").val();
		if(lvprice == 0){
			$('.lvprice-data').hide();
			$('.price-data').show();
		}else{
			$('.lvprice-data').show();
			$('.price-data').hide();
		}
		layui.form.on('radio(commission_money_type)',function(data){
			$('.commission_money_type').hide();
			$('.commission_money_type'+data.value).show();
		});
		layui.form.on('radio(commission_score_type)',function(data){
			$('.commission_score_type').hide();
			$('.commission_score_type'+data.value).show();
		});
	//var ueditor = UE.getEditor('content');
	layui.form.on('radio(freighttypeset)', function(data){
		if(data.value == '1'){
			$('#setfreight').hide();
			$('#freighttype3').hide();
			$('#freighttype4').hide();
		}else if(data.value == '3'){
			$('#setfreight').hide();
			$('#freighttype3').show();
			$('#freighttype4').hide();
		}else if(data.value == '4'){
			$('#setfreight').hide();
			$('#freighttype3').hide();
			$('#freighttype4').show();
		}else{
			$('#setfreight').show();
			$('#freighttype3').hide();
			$('#freighttype4').hide();
		}
	})
	layui.form.on('radio(commissionset)', function(data){
		$('.commissionset').hide();
		$('#commissionset'+data.value).show();
	});

		layui.form.on('radio(fenhongset)', function(data){
			if(data.value == '1'){
				$('#fenhongset').show();
			}else{
				$('#fenhongset').hide();
			}
		})
		layui.form.on('radio(teamfenhongset)', function(data){
			if(data.value == '1'){
				$('#teamfenhongset1').show();
				$('#teamfenhongset2').hide();
			}else if(data.value == '2'){
				$('#teamfenhongset1').hide();
				$('#teamfenhongset2').show();
			}else{
				$('#teamfenhongset1').hide();
				$('#teamfenhongset2').hide();
			}
		})
		layui.form.on('radio(gdfenhongset)', function(data){
			if(data.value == '1'){
				$('#gdfenhongset1').show();
				$('#gdfenhongset2').hide();
			}else if(data.value == '2'){
				$('#gdfenhongset1').hide();
				$('#gdfenhongset2').show();
			}else{
				$('#gdfenhongset1').hide();
				$('#gdfenhongset2').hide();
			}
		})
		layui.form.on('radio(areafenhongset)', function(data){
			if(data.value == '1'){
				$('#areafenhongset1').show();
				$('#areafenhongset2').hide();
			}else if(data.value == '2'){
				$('#areafenhongset1').hide();
				$('#areafenhongset2').show();
			}else{
				$('#areafenhongset1').hide();
				$('#areafenhongset2').hide();
			}
		})
	layui.form.on('radio(guigeset)',function(data){
		if(data.value == '1'){
			$('#setgg').show();
		}else{
			$('#setgg').hide();
		}
	});

	var oldgglist = {:json_encode($newgglist)};
	$(function(){
		refreshgg();
	})
	function addggtype(){
		var gghtml = '<tr>';
		gghtml += '<td><input type="text" name="ggname" class="layui-input" value="" style="width:120px" placeholder="请输入规格分组"/></td>';
		gghtml += '<td><div><input type="text" class="layui-input" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button></div></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
		gghtml += '</tr>';
		$('#ggnamediv').append(gghtml);
	}
	function addggname(obj){
		var ggnameobj = $(obj).parent().parent().append('<div><input class="layui-input" type="text" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().remove()" style="margin-top:-3px;"><i class="fa fa-remove" style="font-size:14px!important"></i></button></div>');
	}
	layui.form.on('radio(lvpriceset)',function(data){
		refreshgg()
	})
	var specs = [];
	function refreshgg(){
		var haskong = 0
		$('#ggnamediv').find("input").each(function(){
			if($(this).val()=='') haskong = 1
		})
		if(haskong){
			layer.msg('请填写完整');return;
		}
		var lvprice = $("input[name='info[lvprice]']:checked").val();
		specs = [];
		var i=0;
		$('input[name=ggname]').each(function(){
			var ggval = [];
			var j=0;
			$(this).parent().next().find('input').each(function(){
				ggval.push({ 'k':j,'title':$(this).val()});
				j++
			})
			specs.push({ 'k':i,'title':$(this).val(),'items':ggval});
			i++;
		});
		console.log(specs)
		var len = specs.length;
		var newlen = 1; 
		var h = new Array(len); 
		var rowspans = new Array(len); 
		
		var html = '<thead><tr>';
		for(var i=0;i<len;i++){
			html+="<th>" + specs[i].title + "</th>";
			var itemlen = specs[i].items.length;
			if(itemlen<=0) { itemlen = 1 };
			newlen*=itemlen;
			h[i] = new Array(newlen);
			for(var j=0;j<newlen;j++){
				h[i][j] = new Array();
			}
			var l = specs[i].items.length;
			rowspans[i] = 1;
			for(j=i+1;j<len;j++){
				rowspans[i]*= specs[j].items.length;
			}
		}
		//html += '<th>规格编号</th>';
		html += '<th>市场价（元）</th>';
		html += '<th>成本价（元）</th>';
		if(lvprice==1){
			{foreach $levellist as $level}
			html += '<th>{$level.name}（元）</th>';
			{/foreach}
		}else{
			html += '<th>销售价（元）</th>';
		}
		html += '<th>重量（克）</th>';
		html += '<th>库存</th>';
		html += '<th>图片</th>';
		html += '</tr></thead>';
		
		for(var m=0;m<len;m++){
			var k = 0,kid = 0,n=0;
			for(var j=0;j<newlen;j++){
				var rowspan = rowspans[m]; 
				if( j % rowspan==0){
					h[m][j]={ k:specs[m].items[kid].k,title: specs[m].items[kid].title, html: "<td rowspan='" +rowspan + "'>"+ specs[m].items[kid].title+"</td>\r\n",id: specs[m].items[kid].id};
				}else{
					h[m][j]={ k:specs[m].items[kid].k,title:specs[m].items[kid].title, html: "",id: specs[m].items[kid].id};	
				}
				n++;
				if(n==rowspan){
					kid++; if(kid>specs[m].items.length-1) { kid=0; }
					n=0;
				}
			}
		}

		var hh = "";
		for(var i=0;i<newlen;i++){
			hh+="<tr>";
			var ks = [];
			var titles = [];
			for(var j=0;j<len;j++){
				hh+=h[j][i].html; 
				ks.push( h[j][i].k);
				titles.push( h[j][i].title);
			}
			ks2 =ks.join('_');
			ks =ks.join(',');
			titles =titles.join(',');
			if(typeof(oldgglist[ks])!='undefined'){
				var val = oldgglist[ks];
			}else{
				var val = { procode:'',market_price:'',cost_price:'',money_price:'',score_price:'',weight:'100',stock:'1000',givescore:'0',pic:'',lvprice_data:null};
			}
		
			//hh += '<td>';
			//hh += '	<input name="option['+ks+'][procode]" class="layui-input" type="text" style="width:100px" value="'+(val.procode==null?'':val.procode)+'"/>';
			//if(i==0){
			//	hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'procode\')"></i>';
			//}
			// hh += '</td>';
			//hh += '<td>';
			//hh += '	<input name="option['+ks+'][barcode]" class="layui-input" type="text" style="width:100px" value="'+(val.barcode==null?'':val.barcode)+'"/>';
			//if(i==0){
			//	hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'barcode\')"></i>';
			//}
			//hh += '</td>';
			hh += '<td>';
			hh += '	<input name="option['+ks+'][name]" type="hidden" value="'+titles+'" class="layui-input"/><input name="option['+ks+'][market_price]" type="text" class="layui-input" style="width:70px" value="'+(val.market_price==null?'':val.market_price)+'"/>';
			if(i==0){
				hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'market_price\')"></i>';
			}
			hh += '</td>';
			hh += '<td>';
			hh += '	<input name="option['+ks+'][cost_price]" type="text" class="layui-input" style="width:70px" value="'+(val.cost_price==null?'':val.cost_price)+'"/>';
			if(i==0){
				hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'cost_price\')"></i>';
			}
			hh += '</td>';
			if(lvprice==1){
				{foreach $levellist as $lk=>$level}
				hh += '<td>';
				hh += '	<input name="option['+ks+'][money_price_{$level.id}]" type="text" style="width:50px" value="'+(val.lvprice_data==null || val.lvprice_data[{$level.id}]==null?'':val.lvprice_data[{$level.id}].money)+'" class="layui-input" id="levelprice_'+i+'_{$lk}"/> 元+';
				hh += '	<input name="option['+ks+'][score_price_{$level.id}]" type="text" style="width:50px" value="'+(val.lvprice_data==null || val.lvprice_data[{$level.id}]==null?'':val.lvprice_data[{$level.id}].score)+'" class="layui-input" id="levelprice2_'+i+'_{$lk}"/> {:t('积分')}';
				if(i==0){
					{if $lk==0}
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'money_price_{$level.id}\')"></i>';
					{else}
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice(\''+i+'\',\'{$lk}\')"></i>';
					{/if}
				}
				hh += '</td>';
				{/foreach}
			}else{
				hh += '<td>';
				hh += '	<input name="option['+ks+'][money_price]" type="text" style="width:50px" value="'+(val.money_price==null?'':val.money_price)+'" class="layui-input"/> 元+';
				hh += '	<input name="option['+ks+'][score_price]" type="text" style="width:50px" value="'+(val.score_price==null?'':val.score_price)+'" class="layui-input"/> {:t('积分')}';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'money_price\')"></i>';
				}
				hh += '</td>';
			}
			hh += '<td>';
			hh += ' <input name="option['+ks+'][weight]" type="text" style="width:60px" value="'+(val.weight==null?'':val.weight)+'" class="layui-input"/>';
			if(i==0){
				hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'weight\')"></i>';
			}
			hh += '</td>';
			hh += '<td>';
			hh += ' <input name="option['+ks+'][stock]" type="text" style="width:60px" value="'+(val.stock==null?'':val.stock)+'" class="layui-input"/>';
			if(i==0){
				hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'stock\')"></i>';
			}
			hh += '</td>';
			hh += '<td id="ggpic'+ks2+'"><input type="hidden" name="option['+ks+'][pic]" id="ggpicval'+ks2+'" value="'+(val.pic==null?'':val.pic)+'"/><div class="guigeimg"><img class="thumb_img" src="'+(val.pic==null?'':val.pic)+'" style="max-width:50px;"/><a class="layui-imgbox-close guigeimg_close" style="'+(val.pic=='' ||val.pic==null?'display:none':'display:block')+'"    href="javascript:void(0)" onclick="$(this).prev(\'.thumb_img\').attr(\'src\',\'\');$(this).parent().prev(\'input\').val(\'\');$(this).hide();" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a></div> <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval'+ks2+'" upload-preview="ggpic'+ks2+'" type="button">上传</button></td>';
			hh += "</tr>";
		}
		html+=hh;
		$("#ggvaldiv").html(html);
	}
	function plset(name){
		if(name =='procode'){
			var procode = $("input[name$='["+name+"]']").eq(0).val();
			if(procode == '') procode = randomString(6);
			$("input[name$='["+name+"]']").each(function(i,v){
				if(i>0) $(this).val(procode+ '-'+i);
			})
		}else if(name == 'money_price' || name.indexOf('money_price')===0){
			var scorename = name.replace('money_price','score_price');
			$("input[name$='["+scorename+"]']").val($("input[name$='["+scorename+"]']").eq(0).val());
			$("input[name$='["+name+"]']").val($("input[name$='["+name+"]']").eq(0).val());
		}else{
			$("input[name$='["+name+"]']").val($("input[name$='["+name+"]']").eq(0).val());
		}
	}
	function plsetlevelprice(i,k){
		var thisprice = $('#levelprice_'+i+'_'+k).val();
		console.log(thisprice)
		var level0price = $('#levelprice_0_0').val();
		console.log(level0price)
		var pricepercent = thisprice / level0price;
		var thisprice2 = $('#levelprice2_'+i+'_'+k).val();
		var level0price2 = $('#levelprice2_0_0').val();
		var price2percent = thisprice2 / level0price2;
		console.log(pricepercent)
		$("input[name$='][market_price]']").each(function(i2,v2){
			var this_price = ($('#levelprice_'+i2+'_0').val() * pricepercent).toFixed(2);
			console.log(this_price)
			this_price = parseInt(this_price*100)/100;
			$('#levelprice_'+i2+'_'+k).val(this_price);

			var this_price2 = $('#levelprice2_'+i2+'_0').val() * price2percent;
			console.log(this_price2)
			this_price2 = parseInt(this_price2);
			$('#levelprice2_'+i2+'_'+k).val(this_price2);
		})
	}
	function randomString(len) {
	　　len = len || 32;
	　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
	　　var maxPos = $chars.length;
	　　var pwd = '';
	　　for (i = 0; i < len; i++) {
	　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
	　　}
	　　return pwd;
	}

	function gonext(layid){
		$(window).scrollTop(0);
		layui.element.tabChange('mytab', layid);
	}
		
	function showChooseProduct(){
		layer.open({type:2,title:'选择商品',content:"{:url('ShopProduct/chooseproduct')}",area:['900px','600px'],shadeClose:true});
	}
	function choosepro(data){
		$("input[name='info[name]']").val(data.product.name);
		$("input[name='info[pic]']").val(data.product.pic);
		$('#picPreview img').attr('src',data.product.pic)
		$("input[name='info[pics]']").val(data.product.pics);
		if(data.product.pics!=''){
			var pics = data.product.pics.split(',');
			var picshtml = '';
			for(var i=0;i<pics.length;i++){
				picshtml+='<div class="layui-imgbox">';
				picshtml+='	<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval(\'pics\',\'picList\')" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a>';
				picshtml+='	<span class="layui-imgbox-img"><img src="'+pics[i]+'"></span>';
				picshtml+='</div>';
			}
			$('#picList').html(picshtml);
		}
		$("input[name='info[fuwupoint]']").val(data.product.fuwupoint);
		$("input[name='info[sellpoint]']").val(data.product.sellpoint);
		$("input[name='info[procode]']").val(data.product.procode);
		$("input[name='info[sell_price]']").val(data.product.sell_price);
		$("input[name='info[score_price]']").val(data.product.sell_price*100);
		$("input[name='info[money_price]']").val(0);
		$("input[name='info[weight]']").val(data.product.weight);
		$("input[name='info[stock]']").val(data.product.stock);
		$("input[name='info[sales]']").val(data.product.sales);
		
		//ueditor.setContent(data.product.detail);
		var $scope = angular.element(document.querySelector('[ng-controller=FoxController]')).scope();
		$scope.Items = JSON.parse(data.product.detail);
		$scope.focus = $scope.Items[0].id;
		$scope.$apply();
	}
	</script>
	<script>
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		field.specs = JSON.stringify(specs)
		//field['info[detail]'] = ueditor.getContent();
		field['info[detail]'] = geteditordata();
		//console.log(field);return;
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>